package linkedlist;

import java.util.LinkedList;
import java.util.ListIterator;

public class LinkTest {
    public static void main(String[] args) {
        LinkedList<Integer> list = new LinkedList<>();
        list.add(1);
        list.add(2);
        list.add(3);
        list.add(4);
        System.out.println(list);
        System.out.println("=====");
        for (Integer item:list) {
            System.out.print(item+" ");

        }
        System.out.println();
        System.out.println("=====");
        for (int i = 0; i < list.size(); i++) {
            System.out.print(list.get(i)+" ");
            
        }
        System.out.println();
        System.out.println("=====");
        ListIterator<Integer> listIterator = list.listIterator();
        while(listIterator.hasNext()){
            System.out.print(listIterator.next()+" ");
        }
        System.out.println();
        System.out.println("迭代器逆置");
        ListIterator<Integer> listIterator2 = list.listIterator(list.size());
        while (listIterator2.hasPrevious()){
            System.out.print(listIterator2.previous()+" ");
        }

    }
    public static void main1(String[] args) {
        MyLinkedList list = new MyLinkedList();
        list.addLast(1);
        list.addLast(2);
        list.addLast(3);
        list.addLast(4);
        list.addIndex(0,0);
        list.addIndex(5,5);
        list.remove(0);
        list.remove(5);
        list.display();
        System.out.println();
        IList list2 = new MyLinkedList();
        list2.addLast(1);
        list2.addLast(1);
        list2.addLast(1);
        list2.addLast(1);
        list2.addLast(1);
        list2.addLast(1);
        list2.display();
        list2.removeAllKey(1);
        list2.display();

    }
}
